import request from '@/utils/request'

//获取spu列表/admin/product/{page}/{limit}
export const reqSpuList = (page, limit, category3Id) => request({
  url: `/admin/product/${page}/${limit}`,
  method: 'get',
  params: {
    category3Id
  }
})

// 获取品牌列表 /admin/product/baseTrademark/getTrademarkList
export const reqTrademarkList = () => request({
  url: '/admin/product/baseTrademark/getTrademarkList',
  method: 'get'
})

// 获取平台中所有的销售属性 /admin/product/baseSaleAttrList
export const reqSaleAttrList = () => request({
  url: '/admin/product/baseSaleAttrList',
  method: 'get'
})

// 通过id获取spu信息 /admin/product/getSpuById/{spuId}
export const reqSpuById = (spuId) => request({
  url: `/admin/product/getSpuById/${spuId}`,
  method: 'get'
})
// 获取spu图片  /admin/product/spuImageList/{spuId}
export const reqSouImageList = (spuId) => request({
  url: `/admin/product/spuImageList/${spuId}`,
  method: 'get'
})

// 保存/修改spu信息 /admin/product/saveSpuInfo | /admin/product/updateSpuInfo
export const reqSaveSpu = (data) => {
  // 根据有无携带id判断区分添加与修改
  if (data.id) {
    return request({
      url: '/admin/product/updateSpuInfo',
      data,
      method: 'post'
    })
  } else {
    return request({
      url: '/admin/product/saveSpuInfo',
      data,
      method: 'post'
    })
  }
}

// 删除spu /admin/product/deleteSpu/{spuId}
export const reqDeleteSpu = (spuId) => request({
  url: `/admin/product/deleteSpu/${spuId}`,
  method: 'delete'
})
